<!-- 转工单 -->
<template>
	<uni-popup ref="popup" background-color="#fff" @change="onPopup">
		<view class="wrapper u-p-30">
			<view class="u-flex-1 body">
				<evan-form :model="formData" ref="form">
					<evan-form-item label="报修人" prop="repairPeople">
						<text>{{formData.repairPeople}}</text>
					</evan-form-item>
					<evan-form-item label="报修人电话" prop="repairPeoplePhone">
						<u-input input-align="right" v-model="formData.repairPeoplePhone"></u-input>
					</evan-form-item>
					<evan-form-item label="报修科室" prop="department">
						<ItemRow v-model="formData.department" ref="department" chooseType="select-department"></ItemRow>
					</evan-form-item>
					<evan-form-item label="报修时间" prop="time">
						<ItemRow v-model="formData.time" ref="time" chooseType="date-picker-ymd"></ItemRow>
					</evan-form-item>
					<evan-form-item label="项目优先级" prop="degree">

						<ItemRow v-model="formData.degree" dicKey="itemPriority" chooseType="select-dic"></ItemRow>
					</evan-form-item>
					<evan-form-item label="影响范围" prop="rangeType">
						<ItemRow v-model="formData.rangeType" dicKey="faultScope" chooseType="select-dic"></ItemRow>

					</evan-form-item>
					<evan-form-item label="故障分类" prop="faultType">
						<ItemRow v-model="formData.faultType" dicKey="faultClassification" chooseType="select-dic-cascader"></ItemRow>
					</evan-form-item>
					<evan-form-item label="故障描述" prop="faultMemo">
						<u-input input-align="right" type="textarea" v-model="formData.faultMemo" placeholder="请填写故障描述" />
					</evan-form-item>
					<evan-form-item label="指派人员" prop="assignedPeople">
						<ItemRow v-model="formData.assignedPeople" chooseType="select-user"></ItemRow>
					</evan-form-item>
					<evan-form-item label="预计工时(小时)">
						<u-input v-model="formData.expectedTime" />
					</evan-form-item>
				</evan-form>
			</view>

			<view class="u-m-t-20 bottom">
				<HButton @click="onSubmit">确定</HButton>
			</view>
		</view>

	</uni-popup>


</template>
<script>
	import HButton from '@/components/button/index.vue'
	import ItemRow from '@/components/arrow/itemArrow.vue'
	import ProjectApi from '@/apis/project.js'
	export default {
		components: {
			HButton,
			ItemRow
		},
		props: {
			data: {
				type: Object,
				default: () => {
					return {}
				}
			},

		},
		computed: {

		},
		data() {
			return {
				formData: {
					// 报修人
					repairPeople: '',
					// 报修人电话
					repairPeoplePhone: '',
					// 故障分类
					faultType: '',
					// 故障描述
					faultMemo: '',
					// 报修时间
					time: '',
					// 指派人
					assignedPeople: '',
					// 报修科室
					department: null,
					// 预计工时
					expectedTime: '',
					// 项目优先级
					degree: 1,
					// 影响范围
					rangeType: 1,
				},
				rules: {
					repairPeople: [{
						required: true,
						message: '报修人不能为空',
						trigger: 'blur',
					}],
					repairPeoplePhone: [{
						required: true,
						trigger: 'blur',
						message: '电话不能为空',
					}],
					faultType: [{
						required: true,
						message: '故障分类',
					}],
					department: [{
						required: true,
						trigger: 'change',
						message: '请选择报修科室',
					}],
					faultMemo: [{
						required: true,
						trigger: 'blur',
						message: '请填写故障描述',
					}],
					time: [{
						required: true,
						trigger: 'blur',
						message: '请选择报修时间',
					}],
					assignedPeople: [{
						required: true,
						trigger: 'change',
						message: '请选择指派人员',
					}],
					expectedTime: [{
						required: true,
						trigger: 'blur',
						type: 'number',
						message: '工时只能为数字',
						transform: (v) => Number(v),

					}, {
						trigger: 'blur',
						validator: (r, v, cb) => {
							if (parseFloat(v) <= 0 || v === '') {
								return cb(new Error('工时不能为空或者小于0'));
							}
							cb();
						},
					}],
				},
			}
		},

		methods: {
			init() {
				this.$refs.form.setRules(this.rules)

			},
			onLabel(item) {

			},
			onSubmit() {
				this.$refs['form'].validate(async (valid) => {
					if (valid) {
						const params = {
							itemCode: this.data.itemCode,
							user: this.formData.repairPeople,
							phone: this.formData.repairPeoplePhone,
							createTime: this.formData.time,
							deptId: this.formData.department,
							faultRemark: this.formData.faultMemo,
							sendUser: this.formData.assignedPeople,
							reqTime: this.formData.expectedTime,
							faultType: this.formData.faultType,
							degree: this.formData.degree,
							learningId: this.formData.learningId,
							rangeType: this.formData.rangeType,
						};
						console.log(params);
						return
						await ProjectApi.Demand.ToOrder(params, 'order');
						wx.navigateBack()

					}
				});
			},
			onPopup(ev) {
				if (ev.show) {
					this.init()
				} else {}
			},
			openPopUp(data) {
				this.$refs.popup.open('bottom')
				this.formData.repairPeople = data.proposerList[0].sponsor
				this.formData.repairPeoplePhone = data.proposerList[0].phone;

				this.formData.department = data.proposerList[0].organizer || null;
				this.formData.time = this.$options.filters.date(data.startTime);
				this.formData.faultMemo = data.title + data.remark || '';
				this.$refs.time.resetInit(this.$options.filters.date(data.startTime))
				this.$refs.department.resetInit(this.$options.filters.subject(this.formData.department))
			},



		},



	}
</script>

<style lang="scss" scoped>
	.wrapper {
		width: 100%;
		background-color: #fff;
		height: 90vh;
		display: flex;
		flex-direction: column;
	}

	.path {
		font-weight: 400;
		font-size: 28rpx;
		color: #98A5B3;

		&-text {
			color: #409EFF;

		}
	}

	.head {
		height: 10%;
	}

	.body {
		height: 80%;
		overflow: auto;
	}

	.bottom {
		height: 10%;
	}
</style>
